home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 May: Tool Chest / Dev.CD May 97 TC.toast / Sample Code / Toolbox / Live Scroll 1.0 / Sources / Events.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-13  |  3.0 KB  |  185 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Events.c
  3.  
  4.     Contains:    Main event loop and basic keyboard/mouse processing
  5.  
  6.     Written by:    Chris White, Developer Technical Support
  7.     
  8.     Copyright:    © 1996 by Apple Computer, Inc., all rights reserved.
  9.     
  10.     Change History (most recent first):
  11.     
  12.             03/29/96            CW        First release
  13.  
  14. */
  15.  
  16.  
  17. #pragma segment Core
  18.  
  19.  
  20. // System Includes
  21.  
  22. #ifndef __MEMORY__
  23.     #include <Memory.h>
  24. #endif
  25.  
  26. #ifndef __APPLEEVENTS__
  27.     #include <AppleEvents.h>
  28. #endif
  29.  
  30. #ifndef __DIALOGS__
  31.     #include <Dialogs.h>
  32. #endif
  33.  
  34. #ifndef __DESK__
  35.     #include <Desk.h>
  36. #endif
  37.  
  38. #ifndef __WINDOWS__
  39.     #include <Windows.h>
  40. #endif
  41.  
  42.  
  43.  
  44.  
  45. // Application includes
  46.  
  47. #ifndef __BAREBONES__
  48.     #include "BareBones.h"
  49. #endif
  50.  
  51. #ifndef __PROTOTYPES__
  52.     #include "Prototypes.h"
  53. #endif
  54.  
  55.  
  56.  
  57.  
  58. // static includes
  59.  
  60. static void DoMouseDown ( EventRecord* theEvent );
  61. static void DoKey ( EventRecord*theEvent );
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. void EventLoop ( void )
  69. {
  70.     OSErr            theErr;
  71.     EventRecord        theEvent;
  72.     
  73.     
  74.     while ( !gQuit )
  75.     {
  76.         WaitNextEvent ( everyEvent, &theEvent, gSleepTime, nil );    
  77.         
  78.         switch ( theEvent.what )
  79.         {
  80.             case mouseDown: 
  81.                 DoMouseDown ( &theEvent );
  82.             break;
  83.             
  84.             case keyDown:
  85.             case autoKey: 
  86.                 DoKey ( &theEvent );
  87.             break;
  88.             
  89.             case activateEvt: 
  90.                 DoActivate ( &theEvent );
  91.             break;
  92.             
  93.             case updateEvt:
  94.                 DoUpdate ( (WindowRef) theEvent.message );
  95.             break;
  96.             
  97.             case osEvt:
  98.                 if ( (theEvent.message >> 24) & suspendResumeMessage )    // suspend or resume
  99.                 {
  100.                     if ( (theEvent.message >> 24) & resumeFlag )
  101.                         SetCursor ( &qd.arrow );
  102.                     
  103.                     // Modify the event record to look like an activate/deactivate event
  104.                     theEvent.modifiers = theEvent.message;        // Copy suspend/resume flag
  105.                     theEvent.message = (long) FrontWindow ( );    
  106.                     DoActivate ( &theEvent );
  107.                 }
  108.             break;
  109.             
  110.             case kHighLevelEvent:
  111.                 theErr = AEProcessAppleEvent ( &theEvent );
  112.             break;
  113.         }
  114.     }
  115.     
  116.     return;
  117.     
  118. } // EventLoop
  119.  
  120.  
  121.  
  122. static void DoMouseDown ( EventRecord* theEvent )
  123. {
  124.     Point            globalPt = theEvent->where;
  125.     SInt16            windowPart;
  126.     WindowRef        theWindow;
  127.     long            theMenu;
  128.     
  129.     
  130.     windowPart = FindWindow ( globalPt, &theWindow );
  131.     switch ( windowPart )
  132.     {
  133.         case inMenuBar: 
  134.             theMenu = MenuSelect ( globalPt );
  135.             MenuDispatch ( theMenu );
  136.         break;
  137.         
  138.         case inSysWindow:
  139.             // The SystemClick toolbox routine handles system events
  140.             SystemClick ( theEvent, theWindow );
  141.         break;
  142.         
  143.         case inGoAway:
  144.             // We'll quit when the user closes the window
  145.             if ( TrackGoAway ( theWindow, theEvent->where ) )
  146.                 gQuit = true;
  147.         break;
  148.         
  149.         // TO DO: Check order of this switch
  150.         case inGrow:
  151.             DoGrowWindow ( theWindow, theEvent );
  152.         break;
  153.         
  154.         case inDrag:
  155.             DoDragWindow ( theWindow, theEvent );
  156.         break;
  157.  
  158.         case inContent:
  159.             DoContentClick ( theWindow, theEvent );
  160.         break;
  161.     }
  162.     
  163.     return;
  164.     
  165. } // DoMouseDown
  166.  
  167.  
  168.  
  169. static void DoKey ( EventRecord* theEvent )
  170. {
  171.     char keyPressed = (theEvent->message & charCodeMask);
  172.     
  173.     
  174.     // Command keys get handled by the menu handling routines
  175.     if ( theEvent->modifiers & cmdKey )
  176.         MenuDispatch ( MenuKey ( keyPressed ) );
  177.     
  178.     return;
  179.     
  180. } // DoKey
  181.  
  182.  
  183.  
  184.  
  185.